home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_4 / newpoly.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  567 b   |  24 lines  |  [MATF/MATL]

  1. function [C,D] = newpoly(X,Y)
  2. % [C] = newpoly(X,Y)
  3. % [C,D] = lnewpoly(X,Y)
  4. % Construction of the collocation polynomial.
  5. % The method is Newton interpolation.
  6. % X is the list of abscissas, input.
  7. % Y is the list of ordinates, input.
  8. % C is the coefficient list for the polynomial, output.
  9. % D is the divided difference table, output.
  10. n = length(X);
  11. D = zeros(n,n);
  12. D(:,1) = Y';
  13. for j=2:n,
  14.   for k=j:n,
  15.       D(k,j) = (D(k,j-1)-D(k-1,j-1))/(X(k)-X(k-j+1));
  16.   end
  17. end
  18. C = D(n,n);
  19. for k=(n-1):-1:1,
  20.   C = conv(C,poly(X(k)));
  21.   m = length(C);
  22.   C(m) = C(m) + D(k,k);
  23. end
  24.